﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace RogueWarrior.Controller
{
    class CharacterController
    {
        bool mIsRunning = false;
        String mLeftThumbstickDirection;

        public Vector2 update(GamePadState currentGamePadState, Vector2 currentPosition)
        {
            if (currentGamePadState.ThumbSticks.Left.X != 0)
                currentPosition.X += 2 * currentGamePadState.ThumbSticks.Left.X;
            if (currentGamePadState.ThumbSticks.Left.Y != 0)
                currentPosition.Y -= 2 * currentGamePadState.ThumbSticks.Left.Y;
            if (Math.Abs(currentGamePadState.ThumbSticks.Left.X) == 1 || Math.Abs(currentGamePadState.ThumbSticks.Left.Y) == 1)
            {
                this.mIsRunning = true;
            }
            else
            {
                this.mIsRunning = false;
            }
            setLeftThumstickDirection(currentGamePadState);
            return currentPosition;
        }

        public bool getIsRunning()
        {
            return mIsRunning;
        }

        private void setLeftThumstickDirection(GamePadState currentGamePadState)
        {
            if (currentGamePadState.ThumbSticks.Left.X == 1 && currentGamePadState.ThumbSticks.Left.Y == 0)
            {
                this.mLeftThumbstickDirection = "E";
            }
            else if (currentGamePadState.ThumbSticks.Left.X == 0 && currentGamePadState.ThumbSticks.Left.Y == 1)
            {
                this.mLeftThumbstickDirection = "N";
            }
            else if (currentGamePadState.ThumbSticks.Left.X == -1 && currentGamePadState.ThumbSticks.Left.Y == 0)
            {
                this.mLeftThumbstickDirection = "W";
            }
            else if (currentGamePadState.ThumbSticks.Left.X == 0 && currentGamePadState.ThumbSticks.Left.Y == -1)
            {
                this.mLeftThumbstickDirection = "S";
            }
            else if (currentGamePadState.ThumbSticks.Left.X > 0 && currentGamePadState.ThumbSticks.Left.Y > 0)
            {
                this.mLeftThumbstickDirection = "NE";
            }
            else if (currentGamePadState.ThumbSticks.Left.X < 0 && currentGamePadState.ThumbSticks.Left.Y > 0)
            {
                this.mLeftThumbstickDirection = "NW";
            }
            else if (currentGamePadState.ThumbSticks.Left.X > 0 && currentGamePadState.ThumbSticks.Left.Y < 0)
            {
                this.mLeftThumbstickDirection = "SE";
            }
            else if (currentGamePadState.ThumbSticks.Left.X < 0 && currentGamePadState.ThumbSticks.Left.Y < 0)
            {
                this.mLeftThumbstickDirection = "NW";
            }
                

        }

        public String getLeftThumbstickDirection()
        {
            return mLeftThumbstickDirection;
        }
    }
}
